<template>
  <div class="app-container">
    <!-- 对话框(添加 / 修改) -->
    <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="45%" v-dialogDrag append-to-body>
      <el-form  ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="100px">
					<el-form-item label="类型系列" prop="type">
						<el-select v-model="formData.type" placeholder="请选择类型系列">
							  <el-option v-for="dict in this.getDictDatas('team_linetype')" :key="dict.value"
								:label="dict.label" :value="dict.value" />
						</el-select>
						<el-checkbox style="margin-left: 20px;" v-model="formData.breakst">散客线路请打勾</el-checkbox>
					</el-form-item>
                    <el-form-item label="线路名称" prop="name">
                      <el-input v-model="formData.name" placeholder="请输入线路名称" />
                    </el-form-item>
                    <el-form-item label="线路" prop="nameLin">
                      <el-input v-model="formData.nameLin" placeholder="请输入线路" />
                    </el-form-item>
                    
                    <el-form-item label="代号" prop="number">
                      <el-input v-model="formData.number" placeholder="请输入代号" />
                    </el-form-item>
                    <el-form-item label="天数" prop="days">
						<el-input-number v-model="formData.days"  :min="1" :max="20" label="天数"></el-input-number>
                    </el-form-item>
                    <el-form-item label="排序" prop="sort">
                      <el-input v-model="formData.sort" placeholder="请输入排序" />
                    </el-form-item>
                    <el-form-item label="住宿说明" prop="remarkStay">
                      <el-input v-model="formData.remarkStay" placeholder="请输入住宿说明" />
                    </el-form-item>
                    <el-form-item label="注意事项" prop="attention">
                      <el-input v-model="formData.attention" placeholder="请输入注意事项" />
                    </el-form-item>
                    <el-form-item label="是否有效" prop="isEffective">
					  <el-checkbox v-model="formData.isEffective">是否有效</el-checkbox>
					  <el-checkbox v-model="formData.isSingle">是否单订</el-checkbox>
                    </el-form-item>
                    <el-form-item label="使用说明" prop="remak">
                      <el-input v-model="formData.remak" placeholder="请输入使用说明" />
                    </el-form-item>
                   <!-- <el-form-item label="散/团" prop="break">
                      
                    </el-form-item> -->
                    
                   <!-- <el-form-item label="自定义" prop="column1">
                      <el-input v-model="formData.column1" placeholder="请输入自定义" />
                    </el-form-item>
                    <el-form-item label="自定义" prop="column2">
                      <el-input v-model="formData.column2" placeholder="请输入自定义" />
                    </el-form-item>
                    <el-form-item label="自定义" prop="column3">
                      <el-input v-model="formData.column3" placeholder="请输入自定义" />
                    </el-form-item>
                    <el-form-item label="自定义" prop="column4">
                      <el-input v-model="formData.column4" placeholder="请输入自定义" />
                    </el-form-item>
                    <el-form-item label="自定义" prop="column5">
                      <el-input v-model="formData.column5" placeholder="请输入自定义" />
                    </el-form-item> -->
      </el-form>
              <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" :disabled="formLoading">确 定</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import * as LineApi from '@/api/team/line';
      export default {
    name: "LineForm",
    components: {
                    },
    data() {
      return {
        // 弹出层标题
        dialogTitle: "",
        // 是否显示弹出层
        dialogVisible: false,
        // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
        formLoading: false,
        // 表单参数
        formData: {
                            id: undefined,
                            name: undefined,
                            nameLin: undefined,
                            type: undefined,
                            number: undefined,
                            days: undefined,
                            sort: undefined,
                            remarkStay: undefined,
                            attention: undefined,
                            isEffective: undefined,
                            remak: undefined,
                            breakst: undefined,
                            isSingle: undefined,
                            column1: undefined,
                            column2: undefined,
                            column3: undefined,
                            column4: undefined,
                            column5: undefined,
        },
        // 表单校验
        formRules: {
                        name: [{ required: true, message: '线路名称不能为空', trigger: 'blur' }],
                        nameLin: [{ required: true, message: '线路不能为空', trigger: 'blur' }],
                        type: [{ required: true, message: '类型系列不能为空', trigger: 'change' }],
                        days: [{ required: true, message: '天数不能为空', trigger: 'blur' }],
                        breakst: [{ required: true, message: '散/团不能为空', trigger: 'blur' }],
        },
                        };
    },
    methods: {
      /** 打开弹窗 */
     async open(id) {
        this.dialogVisible = true;
        this.reset();
        // 修改时，设置数据
        if (id) {
          this.formLoading = true;
          try {
            const res = await LineApi.getLine(id);
            this.formData = res.data;
            this.title = "修改线路";
          } finally {
            this.formLoading = false;
          }
        }
        this.title = "新增线路";
              },
      /** 提交按钮 */
      async submitForm() {
        // 校验主表
        await this.$refs["formRef"].validate();
                  this.formLoading = true;
        try {
          const data = this.formData;
                  // 修改的提交
          if (data.id) {
            await LineApi.updateLine(data);
            this.$modal.msgSuccess("修改成功");
            this.dialogVisible = false;
            this.$emit('success');
            return;
          }
          // 添加的提交
          await LineApi.createLine(data);
          this.$modal.msgSuccess("新增成功");
          this.dialogVisible = false;
          this.$emit('success');
        } finally {
          this.formLoading = false;
        }
      },
                      /** 表单重置 */
      reset() {
        this.formData = {
                            id: undefined,
                            name: undefined,
                            nameLin: undefined,
                            type: undefined,
                            number: undefined,
                            days: undefined,
                            sort: undefined,
                            remarkStay: undefined,
                            attention: undefined,
                            isEffective: undefined,
                            remak: undefined,
                            breakst: undefined,
                            isSingle: undefined,
                            column1: undefined,
                            column2: undefined,
                            column3: undefined,
                            column4: undefined,
                            column5: undefined,
        };
        this.resetForm("formRef");
      }
    }
  };
</script>